package 观察着模式;


import java.util.HashSet;
import java.util.Set;

public class GuPiao implements Subject {
    private double price;
    private Set<Observe>observers=new HashSet<>();
    public void setPrice(double price){
        this.price=price;
        notifyObservers();
    }

    @Override
    public void attach(Observe observe) {
        observers.add(observe);
    }

    @Override
    public void delete(Observe observe) {
      observers.remove(observe);
    }

    @Override
    public void notifyObservers() {
        for (Observe ob :observers) {
            ob.update(price);
        }
    }
}
